import java.util.Random;

public class Main29 {
    //29、采用面向对象思想设计求两点间的距离，要求这两点的横纵坐标由随机产生在0——20之间的整数，且保证两点不重合。
    public static void main(String[] args) {
        Random random = new Random();

        int x1=0;
        int x2=0;
        int y1=0;
        int y2=0;

        while(x1==x2&&y1==y2){
            x1 = random.nextInt(20)+1;
            y1 = random.nextInt(20)+1;
            x2 = random.nextInt(20)+1;
            y2 = random.nextInt(20)+1;
        }

        System.out.println("坐标分别为：(" + x1 + "," + y1 + ")和(" + x2 + "," + y2 +")" );

        distance distance = new distance(x1,y1,x2,y2);
        System.out.println("距离为：" + distance.getDistance());
    }
}

class distance{
    int x1;
    int y1;
    int x2;
    int y2;

    public distance() {
    }

    public distance(int x1, int y1, int x2, int y2) {
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
    }

    public double getDistance(){
        return Math.sqrt(Math.pow(this.x1-this.x2,2)+Math.pow(this.y1-this.y2,2));
    }

}


